package com.system.Controller;

import com.common.Entity.Result;
import com.github.pagehelper.PageInfo;
import com.system.Entity.GuestBook;
import com.system.Entity.ReplyLog;
import com.system.Service.GuestBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/guestbook")
public class GuestBookController {

    @Autowired
    private GuestBookService guestBookService;

    @PostMapping("/add")
    public Result<Void> add(@RequestBody GuestBook guestBook) {
        guestBookService.addGB(guestBook);
        return Result.success();
    }

    @GetMapping("/getList")
    public Result getList(@RequestParam Integer pageNum,
                                    @RequestParam Integer pageSize,
                                    @RequestParam(required = false) String status) {
        PageInfo<GuestBook> pageInfo = guestBookService.getList(pageNum, pageSize, status);
        return Result.success(pageInfo);
    }


    @DeleteMapping("/delete/{gbId}")
    public Result<Void> delete(@PathVariable("gbId") String gbId) {
        guestBookService.deleteGB(gbId);
        return Result.success();
    }

    @PostMapping("/reply")
    public Result<Void> reply(@RequestBody ReplyLog replyLog) {
        guestBookService.reply(replyLog);
        return Result.success();
    }

    @GetMapping("/replyHistory/{gbId}")
    public Result getReply(@PathVariable("gbId") String gbId) {
        List<ReplyLog> replyLogList = guestBookService.replyHistory(gbId);
        return Result.success(replyLogList);
    }


}
